﻿@using System.Globalization
@using KPIS.GERP.MVC.Classes
@using KPIS.GERP.SERVICE.Model
@model List<hrm_ps_absence>

@{
    ViewBag.Title = "ข้อมูลใบลา";
}

<div style="padding: 0 15px; ">
<h2>@ViewBag.Title</h2>
<h4><img src="~/Images/Icons/add.png" height="14"> @Html.ActionLink("สร้างใบลา", "CreateAbsence", "Absence", null, null)</h4> 
    <table class="tablesorter">
        <thead>
            <tr>
                <th>เลขที่</th>
                <th>ผู้ขอ</th>
                <th>ประเภท</th>
                <th>วันที่เริ่ม</th>
                <th>ช่วงเวลา</th>
                <th>วันที่สิ้นสุด</th>
                <th>ช่วงเวลา</th>
                <th>จำนวน</th>
                <th>หมายเหตุ</th>
                <th>สถานะ</th>
                <th>สถานะ</th>
                @*<th>ปรับปรุงเมื่อ</th>
                <th>ผู้ปรับปรุง</th>*@
                <th>รายละเอียด</th>        
            </tr>
        </thead>
        <tbody>
            @{
                var employeeData = (from e in new GERPContext().hrm_ps_employees select e);
                var absenceTypes = HttpHelper.GetAbsenceTypes();
            } 
            @if (Model != null && Model.Count > 0)
            {
                foreach(var m in Model)
                {
                    var absenceType = (from at in absenceTypes where at.absence_type_seq == m.absence_type_seq select at).FirstOrDefault();
                    var absenceTypeName = absenceType == null ? "" : absenceType.absence_type_name;
                    var emp = (from e in employeeData where e.emp_seq == m.emp_seq select e).FirstOrDefault();
                    var empName = emp == null ? "-" : emp.full_name;
                    
                    <tr title="คลิกที่ 'ดูข้อมูล' เพื่อดูรายละเอียดคำขอที่ @m.absence_seq">
                        <td>@Html.DisplayFor(c=>m.absence_seq)</td>
                        <td>@(empName)</td>
                        <td>@(absenceTypeName)</td>
                        <td>@(m.start_date != null ? m.start_date.Value.ToString("dd/MM/yyyy", new CultureInfo("th-TH")) : "")</td>
                        <td>@(m.start_time == "M" ? "เช้า" : "บ่าย")</td>
                        <td>@(m.end_date != null ? m.end_date.Value.ToString("dd/MM/yyyy", new CultureInfo("th-TH")) : "")</td>            
                        <td>@(m.end_time == "M" ? "เช้า" : "บ่าย")</td>
                        <td>@(m.day_count.Value.ToString("#,##0.##")) วัน</td> 
                        <td>@(m.remarks)</td>
                        <td>@{
                                switch (m.record_status)
                                {
                                    case "A":
                                        @Html.Raw("ผ่านการอนุมัติ")
                                        break;
                                    case "U":
                                        @Html.Raw("มีผลใช้")
                                        break;
                                    case "W":
                                        @Html.Raw("<font color='red'>ยังไม่ส่งขออนุมัติ</font>")
                                        break;
                                    case "P":
                                        @Html.Raw("อยู่ระหว่างพิจารณา")
                                        break;
                                    case "D":
                                        @Html.Raw("ถูกลบ")
                                        break;
                                    case "C":
                                        @Html.Raw("ยกเลิก")
                                        break;
                                }
                            }</td>
                        @*<td>@(m.updated_when != null ? m.updated_when.Value.ToString("dd/MM/yyyy HH:mm", new CultureInfo("th-TH")) : "")</td>
                        <td>@(m.updated_by == 0 ? "-" : (m.updated_by == 0 ? "-" : (from e in employeeData where e.emp_seq == m.updated_by select e.mas_name_prefixes.prefix_name + " " + e.first_name + " " + e.last_name).FirstOrDefault()))</td>
                        *@
                        <td><span title="@m.description" style="cursor:help">@HttpHelper.Substring(m.description, 15, "(มีต่อ)...")</span></td>
                        <td> 
                            @Html.ActionLink("ดูข้อมูล", "ViewDetails", new {RefSeq = m.absence_seq}) 
                            @(m.record_status == "W" ? Html.ActionLink("ลบคำขอ", "Confirm", new {m.emp_seq, m.absence_seq, status = "D", title = ViewBag.Title}) : Html.Raw(""))
                        </td> 
                    </tr>
                }
            }
        </tbody>
    </table>
    
    <div id="pager">
        <form>
        <img src="@Url.Content("~/Images/Icons/first.png")" class="first" />
        <img src="@Url.Content("~/Images/Icons/prev.png")" class="prev" />
        <input type="text" class="pagedisplay" />
        <img src="@Url.Content("~/Images/Icons/play.png")" class="next" />
        <img src="@Url.Content("~/Images/Icons/last.png")" class="last" />
        <select class="pagesize"> 
            <option value="10">10</option>
            <option selected="selected" value="20">20</option>
            <option value="30">30</option>
            <option value="40">40</option>
            <option value="50">50</option>
        </select>
        </form>
    </div>
</div>
  
@section scripts{ 
    <script type="text/javascript">
        jQuery(function($) {
            $("table.tablesorter").tablesorter({ widthFixed: true, widgets: ["zebra", "filter"] })
                .tablesorterPager({ container: $("#pager"), size: $(".pagesize option:selected").val() });
        });
        
    </script>
}